package com.lzx.iteam;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.task.DownloadImageTask;
import com.lzx.iteam.util.StringUtil;

import java.util.ArrayList;

/**
 * Created by zhangshuai on 15-3-16.
 */
public class NameCardActivity extends Activity implements View.OnClickListener{

    private LinearLayout mLayout;
    private TextView mCardName;
    private TextView mCardPhone;
    private TextView mCardCompany;
    private TextView mCardPosition;
    private TextView mCardEmail;
    private TextView mCardAddress;
    private ImageView mCardPhoto;

    private ArrayList<String> mContactDataList;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.name_card_layout);
        initView();
        getData();
        initCardData();

    }

    public void initView(){
        mLayout = (LinearLayout) findViewById(R.id.nc_ll);
        mLayout.setOnClickListener(this);
        mCardName = (TextView) findViewById(R.id.nc_name);
        mCardCompany = (TextView) findViewById(R.id.nc_company);
        mCardPhone = (TextView) findViewById(R.id.nc_phone);
        mCardPosition = (TextView) findViewById(R.id.nc_position);
        mCardPhoto = (ImageView) findViewById(R.id.nc_photo);
        mCardEmail = (TextView) findViewById(R.id.nc_email);
        mCardAddress = (TextView) findViewById(R.id.nc_address);


    }
    public void getData(){
//        mContactId = getIntent().getLongExtra("contact_id", -1L);
        mContactDataList = getIntent().getStringArrayListExtra("contact_data");
    }

    /**
     * 初始化已有名片信息
     */
    private void initCardData() {

//        Bitmap photo = ContactsDBReader.getPhotoByContactId(this, mContactId);
//        if ( photo != null){
//            mCardPhoto.setImageBitmap(photo);
//        }

        if(mContactDataList != null){
            mCardName.setText(mContactDataList.get(0));
            mCardCompany.setText(mContactDataList.get(3));
            if (!StringUtil.isEmpty(mContactDataList.get(4))){
                mCardPosition.setVisibility(View.VISIBLE);
                mCardPosition.setText(mContactDataList.get(4));
            }else{
                mCardPosition.setVisibility(View.GONE);
            }
            mCardPhone.setText(mContactDataList.get(1)+" "+mContactDataList.get(2));
            mCardEmail.setText(mContactDataList.get(5));
            mCardAddress.setText(mContactDataList.get(6));

            String avatar = mContactDataList.get(7);
            if (!StringUtil.isEmpty(avatar) && !"Nona".equals(avatar)){
                DownloadImageTask downloadImageTask = new DownloadImageTask(mCardPhoto);
                downloadImageTask.execute(avatar);
            }
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.nc_ll:
                NameCardActivity.this.finish();
                break;
        }
    }
}
